import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/trademark/list',
    name: 'Trademark',
    component: () => import('@/views/product/trademark'),
    meta: { title: '品牌管理' }
  },
  {
    path: '/attr/list',
    name: 'Attr',
    component: () => import('@/views/product/attr'),
    meta: { title: '属性管理' }
  },
  {
    path: '/sku/list',
    name: 'Sku',
    component: () => import('@/views/product/sku'),
    meta: { title: 'sku管理' }
  },
  {
    path: '/spu/list',
    name: 'Spu',
    component: () => import('@/views/product/spu'),
    meta: { title: 'spu管理' }
  }
]

const createRouter = () =>
  new Router({
    mode: 'history', // require service support
    base: window.__POWERED_BY_QIANKUN__ ? '/product' : '/',
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
